// Ionic_SDK
// 
// 保佑没Bug 
//
// Created by AS on 2019/5/21. 
//
// Copyright © 2018 AS. All rights reserved.
// 

#import "ReplyModel.h"

@implementation ReplyModel
+ (NSDictionary *)mj_replacedKeyFromPropertyName{
    return @{@"Id": @"id"};
}





-(NSString *)createTime{
    
    NSDateFormatter *fmt = [[NSDateFormatter alloc]init];
    //    fmt.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"];
    fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *createDate = [fmt dateFromString:_createTime];
    NSDate *new = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    NSDateComponents *cmps = [calendar components:unit fromDate:createDate toDate:new options:0];
    if([createDate isThisYear]){ //是否是今年
        if([createDate isYesterday]){ //是否是昨天
            fmt.dateFormat = @"昨天 HH:mm";
            return [fmt stringFromDate:createDate];
        }else if([createDate isToday]){ //是否是今天
            if(cmps.hour >= 1){
                return [NSString stringWithFormat:@"%d小时前",(int)cmps.hour];
            }else if(cmps.minute >= 1 && cmps.hour < 1){
                return [NSString stringWithFormat:@"%d分钟前",(int)cmps.minute];
            }else{
                return @"刚刚";
            }
        }else{
            fmt.dateFormat = @"MM-dd HH:mm";
            return [fmt stringFromDate:createDate];
        }
    }else{
        fmt.dateFormat = @"yyyy-MM-dd";
        return [fmt stringFromDate:createDate];
    }
}

-(void)setReplyModel:(ReplyModel *)replyModel{
    _replyModel = replyModel;
    
    NSMutableAttributedString *attriText = [[NSMutableAttributedString alloc]init];
    NSAttributedString *attContent = [[NSAttributedString alloc]initWithString:_content];
    [attriText appendAttributedString:attContent];
    NSString *nick = [NSString stringWithFormat:@" @%@",replyModel.nickName];
    NSAttributedString *attNick = [[NSAttributedString alloc]initWithString:nick attributes:@{NSForegroundColorAttributeName : HexRGB(0xff8110)}];
    [attriText appendAttributedString:attNick];
    
    NSAttributedString *attReplyContent = [[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@": %@",replyModel.content] attributes:@{NSForegroundColorAttributeName : HexRGB(0x888888)}];
    [attriText appendAttributedString:attReplyContent];
    _attributedText = attriText;
    _content1 = [NSString stringWithFormat:@"%@ @%@: %@",_content,replyModel.nickName,replyModel.content];
}


@end



@implementation ReplyModelF

-(void)setModel:(ReplyModel *)model{
    _model = model;
    
    CGFloat margin = 10;
    
    self.avatarF = CGRectMake(12, 12, 40, 40);
    
    CGSize size = [model.nickName sizeWithFont:Font14];
    self.nameF = CGRectMake(CGRectGetMaxX(self.avatarF) + margin, 15, size.width, size.height);
    
    size = [model.createTime sizeWithFont:Font12];
    
    self.createTimeF = CGRectMake(self.nameF.origin.x,CGRectGetMaxY(self.nameF) + 3, size.width + 50, size.height);
    
    CGFloat x = CGRectGetMidX(self.nameF) + 12;
    if (model.replyModel) {
        size = [model.content1 sizeWithFont:Font16 maxW:ScreenWidth - x];
        self.contentF = CGRectMake(self.nameF.origin.x, CGRectGetMaxY(self.createTimeF) + 10, size.width, size.height);
    }else{
        size = [model.content sizeWithFont:Font16 maxW:ScreenWidth - x];
        self.contentF = CGRectMake(self.nameF.origin.x, CGRectGetMaxY(self.createTimeF) + 10, size.width, size.height);
    }
    
    
    self.cellHeight = CGRectGetMaxY(self.contentF) + 40;
    
}


@end
